import 'package:flutter/material.dart';
import 'package:flutterapp/fileUpload/camera.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutterapp/fileUpload/photo.dart';
import 'package:flutter/cupertino.dart';

void main() => runApp(HttpDemo());

class HttpDemo extends StatefulWidget {
  @override
  _HttpDemoState createState() => _HttpDemoState();
}

class _HttpDemoState extends State<HttpDemo> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    this._getData();
  }


  String _background_color='';
  String _dpi='';
  String _mm='';
  String _px='';

  //请求数据
  _getData() async{
    var apiUrl="http://z.qingchan.vip:8086/getsize?specification_code=020";
    var result=await http.get(apiUrl);
    if(result.statusCode==200){
      setState(() {
        this._background_color=json.decode(result.body)['data']['background_color'];
        this._dpi=json.decode(result.body)['data']['dpi'];
        this._mm=json.decode(result.body)['data']['mm'];
        this._px=json.decode(result.body)['data']['px'];
      });
    }else{
      print("失败${result.statusCode}");
    }
  }


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white,
          title: Text(
              '证件采集系统',
            style: TextStyle(
              color: Colors.black,
            ),
          ),
        ),
        body:Column(
          children: <Widget>[
            Container(
              height: 600,
              child: ListView(
                children: <Widget>[
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Column(
                        children: <Widget>[
                          Container(
                            width: 150,
                            padding: EdgeInsets.all(15),
                            child: Image.asset(
                              'images/fileUpload/4.png',
                              fit: BoxFit.cover,
                            ),
                          ),
                          Text(
                            '新版社保卡',
                            style: TextStyle(
                              fontSize: 30,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                          Container(
                            height: 50,
                          ),
                        ],
                      ),
                    ],
                  ),
                  Container(
                      padding: EdgeInsets.all(15),
                      height: 60,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Container(
                              child: Center(
                                child: Text('背景色',
                                  style: TextStyle(

                                  ),
                                ),
                              )
                          ),
                          Container(
                              child: Center(child: Text(this._background_color))
                          ),
                        ],
                      )
                  ),
                  Divider(
                    color: Colors.black,
                  ),
                  Container(
                    padding: EdgeInsets.all(15),
                    height: 60,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Container(
                          child: Center(child: Text('分辨率')),
                        ),
                        Container(
                          child: Center(child: Text(this._dpi+"dpi")),
                        ),
                      ],
                    ),
                  ),
                  Divider(
                    color: Colors.black,
                  ),
                  Container(
                    padding: EdgeInsets.all(15),
                    height: 60,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Container(
                          child: Center(child: Text('像素/冲印尺寸')),
                        ),
                        Container(
                          child: Center(child: Text(this._px+"px"+'/'+this._mm+"mm")),
                        ),
                      ],
                    ),
                  ),
                  Divider(
                    height: 1,
                    color: Colors.black,
                  ),
                  Container(
                    padding: EdgeInsets.fromLTRB(15, 10, 15, 0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Text('拍摄要求: '),
                        Text('1.作为法定证件，新版社保卡相片要求真实反映申领人容貌特征， 不得使用任何图像编辑软件进行任何修饰、修改或美化操作，必须保证拍摄相片的真实还原性;'),
                        Text('2.照片应为正面头像，拍摄时头部、脸部不得歪斜或侧转;'),
                        Text('3.拍摄前应清洗脸部汗水和油污,油性皮肤应在脸部擦拭少许粉，不能化浓妆;'),
                        Text('4.拍摄时应穿着深色有领衣服,穿浅色系列服装者应穿着摄影点提供的服装拍摄;'),
                        Text('5.拍照时应脱帽，不得染发(不包括将白发染成黑发)、佩戴各种首饰或使用“美瞳”隐形眼镜，不得戴有色镜片，戴眼镜拍摄照片，镜片不能有反光;'),
                        Text('6.拍摄前应将头发整理好,头发不得遮挡面部，长发者应露出双耳,发髻不得盘在头顶。'),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              height: 50,
              child: Container(
                padding: EdgeInsets.fromLTRB(10, 5, 10, 5),
                width: 500,
                child: FlatButton(
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(100),
                  ),
                  child: Text(
                    '采集照片',
                    style: TextStyle(
                      fontSize: 18,
                    ),
                  ),
                  textColor: Colors.white,
                  color: Colors.blue,
                  onPressed: (){
                    //从底部弹出一个对话框
                    showModalBottomSheet(
                      context: context,
                      builder: (BuildContext context) {
                        return new Container(
                          width: 100.0,
                          height: 200.0,
                          color: Colors.grey,
                          child: Column(
                            children: <Widget>[
                              Container(
                                padding: EdgeInsets.fromLTRB(0, 5, 0, 5),
                                child: Text(
                                  '选择操作',
                                  style: TextStyle(
                                    fontSize: 20,
                                  ),
                                ),
                              ),
                              Container(
                                child: Row(
                                  children: <Widget>[
                                    Column(
                                      children: <Widget>[
                                        Container(
                                          width: 110,
                                          height: 110,
                                          child: IconButton(
                                            icon: Image.asset('images/fileUpload/5.png'),
                                            onPressed: (){
                                              Navigator.of(context).push(
                                                MaterialPageRoute(
                                                  builder: (context)=> CameraPage(),
                                                ),
                                              );
                                            },
                                          ),
                                        ),
                                        Container(
                                          child: Text('相机'),
                                        ),
                                      ],
                                    ),
                                    Column(
                                      children: <Widget>[
                                        Container(
                                          width: 100,
                                          height: 100,
                                          margin: EdgeInsets.fromLTRB(0, 5, 0, 5),
                                          child: IconButton(
                                            icon: Image.asset('images/fileUpload/6.png'),
                                            onPressed: (){
                                              Navigator.of(context).push(
                                                MaterialPageRoute(
                                                  builder: (context)=> PhotoPage(),
                                                ),
                                              );
                                            },
                                          ),
                                        ),
                                        Container(
                                          child: Text('相册'),
                                        ),
                                      ],
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                        );
                      },
                    ).then((val) {
                      print(val);
                    });
                  },
                ),
              ),
            )
          ],
        )
      ),
    );
  }
}

